package users

import (
	"itodo/core/dao/table"
	"itodo/core/dao/userdao"
	"itodo/core/localwrap"

	"github.com/RocksonZeta/wrap/errs"
	"github.com/RocksonZeta/wrap/utils/hashutil"
)

func Password(str string) string {
	return hashutil.Md5(hashutil.Md5(str))
}

type UserPrivates struct{}

type SigninParam struct {
	Email    string
	Password string
}

func (u UserPrivates) Signin(param SigninParam) (table.UserPrivate, *errs.Err) {
	d := userdao.UserPrivates{RedisedMysql: localwrap.GetRedisedMysql()}
	defer d.Close()
	r := d.GetByEmail(param.Email)
	if r.Id <= 0 {
		return r, errs.NewUserError(100, "Email not exists")
	}
	if r.Password != Password(param.Password) {
		return table.UserPrivate{}, errs.NewUserError(101, "Password error")
	}
	r.Password = ""
	return r, nil

}

type SignupParam struct {
}

func (u UserPrivates) Signup(param SigninParam) {

}
